package com.example.studentaihouduan.Config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

@Configuration
public class AppConfig {

    @Value("${ai.api.key}")
    private String apiKey;

    @Value("${ai.api.slug}")
    private String slug;

    @Value("${ai.api.url}")
    private String apiUrl;

    // 创建 apiUrl Bean
    @Bean(name = "apiUrl")
    public String apiUrl() {
        return this.apiUrl;
    }

    // 创建 slug Bean
    @Bean(name = "slug")
    public String slug() {
        return this.slug;
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public HttpHeaders aiHeaders() {
        HttpHeaders headers = new HttpHeaders();
        headers.set("Authorization", "Bearer " + apiKey);
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        return headers;
    }
}